Imports System.Web

Public Class Rpt_Fields
    Private Const Q As String = Chr(34)

    Public Sub ShowFieldDetail( _
                    ByVal lTableID As Long, _
                    ByVal lRevID As Long, _
                    ByVal bShowEditFields As Boolean)

        Dim oFactory As New SQLAutoDocLib.Field_Factory

        HttpContext.Current.Response.Write("<table class=" & Q & "wmObjectDetail_T" & Q & ">")

        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectDetail_TH" & Q & ">")

        HttpContext.Current.Response.Write("<td class=" & Q & "wmObjectDetail_ZU" & Q & ">")
        HttpContext.Current.Response.Write("Nullable")
        HttpContext.Current.Response.Write("</td>")

        HttpContext.Current.Response.Write("<td class=" & Q & "wmObjectDetail_ZN" & Q & ">")
        HttpContext.Current.Response.Write("Name")
        HttpContext.Current.Response.Write("</td>")

        HttpContext.Current.Response.Write("<td class=" & Q & "wmObjectDetail_ZT" & Q & ">")
        HttpContext.Current.Response.Write("Type")
        HttpContext.Current.Response.Write("</td>")

        HttpContext.Current.Response.Write("<td class=" & Q & "wmObjectDetail_ZS" & Q & ">")
        HttpContext.Current.Response.Write("Precision/Scale")
        HttpContext.Current.Response.Write("</td>")

        HttpContext.Current.Response.Write("</tr>")

        Dim bAlternatingRow As Boolean = False

        For Each oField As SQLAutoDocLib.Field In oFactory.GetAllFieldsForTable(lTableID, lRevID)
            With oField
                If bAlternatingRow = False Then
                    HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectDetail_T" & Q & ">")
                Else
                    HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectDetail_TA" & Q & ">")
                End If

                HttpContext.Current.Response.Write("<td><img src=" & Q & "images/" & CheckedImage(.IsNotNull) & Q & " border=" & Q & "0" & Q & "/></td>")
                HttpContext.Current.Response.Write("<td>" & .Name & "</td>")
                HttpContext.Current.Response.Write("<td>" & .Type & "</td>")
                HttpContext.Current.Response.Write("<td>")
                HttpContext.Current.Response.Write(.Precision)
                If .Scale <> -999 Then
                    HttpContext.Current.Response.Write("/" & .Scale)
                End If
                HttpContext.Current.Response.Write("</td>")

                HttpContext.Current.Response.Write("</tr>")

                If .DefaultValue > "" Then
                    If bAlternatingRow = False Then
                        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_T" & Q & ">")
                    Else
                        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
                    End If
                    HttpContext.Current.Response.Write("<td>&nbsp;</td>")
                    HttpContext.Current.Response.Write("<td colspan=" & Q & 3 & Q & ">")
                    HttpContext.Current.Response.Write("<span class=" & Q & "wmObjectDetail_Default" & Q & ">Default: </span>")
                    HttpContext.Current.Response.Write(.DefaultValue)
                    HttpContext.Current.Response.Write("</td>")
                    HttpContext.Current.Response.Write("</tr>")
                End If

                If .Constraint > "" Then
                    If bAlternatingRow = False Then
                        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_T" & Q & ">")
                    Else
                        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
                    End If
                    HttpContext.Current.Response.Write("<td>&nbsp;</td>")
                    HttpContext.Current.Response.Write("<td colspan=" & Q & 3 & Q & ">")
                    HttpContext.Current.Response.Write("<span class=" & Q & "wmObjectDetail_Constraint" & Q & ">Constraint: </span>")
                    HttpContext.Current.Response.Write(.Constraint)
                    HttpContext.Current.Response.Write("</td>")
                    HttpContext.Current.Response.Write("</tr>")
                End If

                If bShowEditFields _
                        OrElse .Desc > "" Then

                    If bAlternatingRow = False Then
                        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_T" & Q & ">")
                    Else
                        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
                    End If
                    HttpContext.Current.Response.Write("<td>&nbsp;</td>")
                    HttpContext.Current.Response.Write("<td colspan=" & Q & 3 & Q & ">")

                    If bShowEditFields Then
                        HttpContext.Current.Response.Write("<input type=" & Q & "hidden" & Q & _
                                             " name=" & Q & "fid" & Q & _
                                             " value=" & Q & .ID & Q & "/>")

                        HttpContext.Current.Response.Write("<input type=" & Q & "text" & Q & _
                                             " name=" & Q & "desc:" & .ID & Q & _
                                             " value=" & Q & .Desc & Q & _
                                             " style=" & Q & "margin-left: 10px; width: 350px;" & Q & "/>")
                    Else
                        HttpContext.Current.Response.Write("<span class=" & Q & "wmObjectDetail_Desc" & Q & ">Desc: </span>")
                        HttpContext.Current.Response.Write(.Desc)
                    End If

                    HttpContext.Current.Response.Write("</td>")
                    HttpContext.Current.Response.Write("</tr>")
                End If
            End With

            bAlternatingRow = Not bAlternatingRow
        Next
        HttpContext.Current.Response.Write("</table>")
    End Sub

    Private Function CheckedImage(ByVal bValue As Boolean) As String
        If bValue Then
            Return "yes.gif"
        Else
            Return "whitebox.gif"
        End If
    End Function
End Class
